<template>
  <div class="goods-list">
      <div class="goods-item" v-for="item in goodsList" :key="item.id" @click = "goGoodsinfo(item.id)">
          <img :src="item.img_url" alt="">
          <h3>{{item.title}}</h3>
          <div class="goods-info">
              <p class="price">
                  <span class="now">￥{{item.sell_price}}</span>
                  <span class="old">￥{{item.market_price}}</span>
              </p>
              <p class="sell">
                  <span>热卖中</span>
                  <span>剩{{item.stock_quantity}}件</span>
              </p>
          </div>
      </div>
       <mt-button type="danger" size = "large" @click = "getMore">加载更多</mt-button>
  </div>
</template>
<script>
export default {
  data () {
    return {
      pageindex: 1,
      goodsList: []
    }
  },
  created () {
    this.getGoodsList()
  },
  methods: {
    //   获取商品列表
    getGoodsList () {
      this.$http.get('api/getgoods?pageindex=' + this.pageindex).then(result => {
        if (result.body.status === 0) {
          this.goodsList = this.goodsList.concat(result.body.message)
        }
      })
    },
    getMore () {
      this.pageindex++
      this.getGoodsList()
      console.log(this.pageindex)
    },
    goGoodsinfo (id) {
      this.$router.push('/home/goodsinfo/' + id)
    }
  }
}
</script>
<style lang="css" scoped>
.goods-list{
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    padding: 7px;
}
.goods-list .goods-item{
    box-shadow: 0 0 4px #ccc;
    width: 49%;
    border:1px solid #ccc;
    margin: 3px 0;
    padding: 2px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
}
.goods-list .goods-item  h3{
    font-size: 16px;
    font-weight: 800;
}
.goods-list .goods-item img{
    width:100%
}
.goods-list .goods-item .goods-info {
    background-color: #eee;
}
.goods-list .goods-item .goods-info p{
    margin: 0;
    padding: 5px;
}
.goods-list .goods-item .goods-info .price .now{
    color: red;
    font-weight: 600;
    font-size: 16px;
}
.goods-list .goods-item .goods-info .price .old{
    text-decoration: line-through;
    font-size: 12px;
    margin-left: 10px;
}
.goods-list .goods-item .goods-info .sell{
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}
.mint-button{
    margin-bottom: 50px;
}
</style>
